package com.agile.leetcode.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/6 18:34
 */
public class Demo {
    public static void main(String[] args) {
        // 输入第一个数
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入下边界");
        int a = scanner.nextInt();
        // 接收第二个数
        System.out.println("请输入上边界");
        int b = scanner.nextInt();
        // 判断边界
        if (a < 1 || b < 1) {
            System.out.println("输入参数不合法，请重新输入");
            return;
        }
        List<List<Integer>> list = new ArrayList<>(10);
        double sum = 0;
        // 循环遍历
        for (int i = a; i <= b; i++) {
            for (int j = i + 1; j <= b; j++) {
                sum = i * i + j * j;
                // 判断是否是平方数
                double sum1 = Math.sqrt(sum);

                String str = sum1 + "";
                int i1 = str.lastIndexOf(".");
                str = str.substring(i1 + 1);
                int index = str.length();
                if (index > 1 || Math.sqrt(sum) > b) {
                    continue;
                } else {
                    boolean flag = true;
                    List<Integer> list3 = new ArrayList<>(10);
                    for (int k = 2; k < i; k++) {
                        for (int l = k ; l < i; l++) {
                            if (k * l == i) {
                                list3.add(k);
                                list3.add(l);
                            }
                        }
                    }
                    for (int k = 2; k <j ; k++) {
                        for (int l =k; l < j; l++) {
                           if (k*l==j){
                               if (list3.contains(k)||list3.contains(j)){
                                   flag=false;
                               }
                           }
                        }
                    }
                    int m=(int)Math.sqrt(sum);
                    for (int k = 2; k < m; k++) {
                        for (int l = k; l < m; l++) {
                            if (k*l==m){
                                if (list3.contains(k)||list3.contains(j)){
                                    flag=false;
                                }
                            }
                        }
                    }
                    if (flag) {
                        list.add(Arrays.asList(i, j, (int) Math.sqrt(sum)));
                    }

                }
            }
        }
        for (List<Integer> list1 : list) {
            for (int i = 0; i < list1.size(); i++) {
                System.out.print(list1.get(i)+" ");
            }
            System.out.println();
        }
        if (list.size()==0){
            System.out.println("NA");
        }
    }
}
